package com.one.monitoring.utils;

import com.mongodb.*;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;

import java.util.Arrays;


/**
 * @author lxh
 * @description 描述
 * @time 2023/11/17 14:34
 **/
@Slf4j
public class MongoDBTestUtils {

    public static Integer testMongoDB(){
        try {
            String url = "mongodb://root:dTi64O28qT@16.162.198.48:27017";
            MongoClient mongoClient = new MongoClient(new MongoClientURI(url));
            MongoDatabase database = mongoClient.getDatabase("wallet-onepay");
            MongoCollection<Document> normalConfig = database.getCollection("normal_config");
            if (normalConfig != null && normalConfig.count() > 0){
                log.info("mongodb连接成功！");
                mongoClient.close();
                return 1;
            }
        }catch (Exception e){
            log.info("mongodb连接异常:{}",e.getMessage());
        }
        return 2;
    }

    public static void main(String[] args) {
        Integer integer = testMongoDB();
        System.out.println(integer);
    }
}
